﻿using M_ApiResult;
using M_Quality.API.Application.Command.QualitygroupCommand;
using M_Quality.API.Application.Command.QualityinspectionCommand;
using M_Quality.API.Application.Command.QualityPlanCommand;
using M_Quality.API.Application.Command.QualityProgromCommand;
using M_Quality.Domain;
using M_Quality.Domain.Dto;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace M_Quality.API.Controllers
{
    /// <summary>
    /// 质检方案
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class QualityProgromController : ControllerBase
    {
        protected readonly IMediator mediator;

        public QualityProgromController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddQualitProgrom(QualityProgromCreateCommand command)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {

                result.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;

        }
        /// <summary>
        /// 反填
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<QualityfangDto<Qualityinspection>>> BackfillQualityspection([FromQuery] QualityPianByidCommand command)
        {
            ApiResult<QualityfangDto<Qualityinspection>> result = new ApiResult<QualityfangDto<Qualityinspection>>();
            try
            {
                result.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;

        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> UpdateQualityspection(QualityProgromUpdateCommand command)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {

                result.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;

        }
    }
}
